*****************************************************************
*																*
*				Title: 1_regressions_metal		 	 	   	*		
*															    *
*****************************************************************


/*  ================================  NOTES  ================================

+ PURPSOSE:
	
	In this do-file we run regressions for the metal sector and output the regressions' results
	 
		
+ Inputs:

		* 1. final/panel_metallurgy.dta


==============================  TOP MATTER ==============================*/

	*DATA
	global proc_data "`pdir'/data"
	global output "`pdir'/outputs/main_paper"


******************************** END HEADER ********************************

use "$proc_data/panel_metallurgy.dta", clear



********************************************************************************
******************************       FIGURES	 	****************************
********************************************************************************


************	Figure 1 (Panel B). ********************************************
*** Changes in the Productivity Distributions in Metallurgy	 


twoway (kdensity logYmeanoverL_real if year == 1811, bwidth(0.2) lcolor(gs6) lpattern(dash) lwidth(thick)) ///
 (kdensity logYmeanoverL_real if year == 1840, bwidth(0.2) lcolor(navy) lpattern(solid) lwidth(thick)), ///
 ytitle(Kernel density, size(large))  ylabel(0 (0.1) 0.5 , labsize(medlarge) )  xtitle(ln(Output per worker), size(large)) xscale(range(2 10)) xlabel(2(2)10, labsize(medlarge)) ylabel(, labsize(medlarge)) ///
 legend(order(1 "1811" 2 "1840") position(9) ring(0) cols(1) size(large))  scheme(s1color)
	graph export "$output/Figures/Figure_1B.eps", replace
	graph export "$output/Figures/Figure_1B.pdf", replace


	
	
************	Figure 2 (Panel B). ********************************************
*** Productivity Growth at Different Quantiles of the Distribution 	

forv i=10(10)90{
	preserve	
		xi:qreg logYmeanoverL_real_pa i.year, quantile(`i') vce(robust)
		est store est`i'
	restore
}

coefplot est10 || est20 || est30 || est40 || est50 || est60 || est70 || est80 || est90, keep(_I*) vertical pstyle(p7) color(black) ciopts(color(black) recast(rcap)) citop legend(off) xtitle("Decile", size(large)) ytitle(Avg annual growth rate (%), size(large))  ylabel(0 (1) 4, labsize(medlarge))  scheme(s1color) bycoefs bylabels("0.1" "0.2" "0.3" "0.4" "0.5" "0.6" "0.7" "0.8" "0.9")

 
graph export "$output/Figures/Figure_2B.eps", replace
graph export "$output/Figures/Figure_2B.pdf", replace
	
	
***************************************************************************
*********************************		TABLES	 	***********************
***************************************************************************
	
************	Table 1 (Panel B). ********************************************
*** Annual Productivity Growth (in %) at Different Quantiles of the Distribution	 	***********

estimates clear
quietly{
	eststo: xi:reg logYmeanoverL_real_pa i.year,  vce(robust)
	local N_obs = e(N)
	eststo: xi:qreg logYmeanoverL_real_pa i.year, quantile(10) vce(robust)
	eststo: xi:qreg logYmeanoverL_real_pa i.year, quantile(25) vce(robust)
	eststo: xi:qreg logYmeanoverL_real_pa i.year, quantile(50) vce(robust)
	eststo: xi:qreg logYmeanoverL_real_pa i.year, quantile(75) vce(robust)
	eststo: xi:qreg logYmeanoverL_real_pa i.year, quantile(90) vce(robust)
	
}			
	
estout using "$output/Tables/Table_1B.tex", replace label drop(_cons) order($show ) ///
    rename (_Iyear_1840 "Metallurgy\ (1811-1840)")  ///
    mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs' "" " "\\[-0.15cm]") varlabels(, end("\addlinespace[0.00cm] ")) ///
    cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none)
	
*Redundancy in reported number of observations in the last column is fixed by hand after generating the table		
	

	
